﻿using Admin2024.Application.Contracts.Role;
using Admin2024.Domain.DomainService.System.RoleService;
using Admin2024.Domain.Entity.System;
using Admin2024.Domain.IDomainService.System.IRoleService;
using Admin2024.Domain.ObjValue;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Admin2024.Application.Role
{
    public class RolePermissionAssignService : IRolePermissionAssignService
    {

        private readonly IRolePermissionService rolePermissionService;

        public RolePermissionAssignService(IRolePermissionService rolePermissionService)
        {
            this.rolePermissionService = rolePermissionService;
        }

        //给角色分配权限
        public async  Task<DomainResult<string>> CreatePermission(Guid roleId, Guid PerId)
        {
            var appRolePer  =  await rolePermissionService.CreatePermission(roleId, PerId);
            if(!appRolePer.IsSuccess) {
                return DomainResult<string>.Error(appRolePer.Message);
            }
            return DomainResult<string>.Success(appRolePer.Data);
        }

        //删除角色权限
        public async Task<DomainResult<string>> DeletePermission(Guid roleId, Guid PerId)
        {
            var appRolePer = await rolePermissionService.DeletePermission(roleId, PerId);
            if (!appRolePer.IsSuccess)
            {
                return DomainResult<string>.Error(appRolePer.Message);
            }
            return DomainResult<string>.Success(appRolePer.Data);
        }


        //获取角色所有权限
        public async Task<DomainResult<List<AppPermission>>> GetListRolePermission(Guid roleId)
        {
            var appRolePerList = await rolePermissionService.GetListRolePermission(roleId);
            if (!appRolePerList.IsSuccess)
            {
                return DomainResult<List<AppPermission>>.Error(appRolePerList.Message);
            }
            return DomainResult<List<AppPermission>>.Success(appRolePerList.Data);
        }
    }
}
